package com.maigao.util;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.concurrent.ArrayBlockingQueue;

public class UserNameUtil {
    private static ArrayBlockingQueue<String> userNameList;

    public static String getUserName() {
        try {
            if (userNameList == null) {
                userNameList = new ArrayBlockingQueue<>(1000);
            }
            if (userNameList.size() == 0) {
//                System.out.println("=================重新获取==============");
                String content = HttpUtils.doGet("https://www.qmsjmfb.com/erciyuan.php");
                Document document = Jsoup.parse(content);
                Elements name_show = document.body().getElementsByClass("name_box container");
                Element element = name_show.get(0);
                Elements liList = element.getElementsByTag("li");
                for (int i = 0; i < liList.size(); i++) {
                    userNameList.put(liList.get(i).text());
                }
            }
            return userNameList.take();
        } catch (Exception ex) {
            ex.printStackTrace();
            return "";
        }
    }
}
